<?php

namespace app\controller;

use app\repository\RoomRepository;
use support\Request;

class RoomController extends BaseController
{
    protected $repository;

    public function __construct(RoomRepository $repository)
    {
        $this->repository = $repository;
    }

    public function add(Request $request)
    {
        $data['name'] = $request->input("name");
        $data['tcp_ip'] = $request->input("tcp_ip");
        $data['udp_ip'] = $request->input("udp_ip");
        $data['inside_pc_ip'] = $request->input("inside_pc_ip");
        $data['outside_pc_ip'] = $request->input("outside_pc_ip");
        $data['is_admin'] = $request->input("id_admin",0);
        if (!$data['name'] ){
            return $this->error("参数缺失");
        }
        $res = $this->repository->add($data);
        return $this->res($res);
    }

    public function edit(Request $request)
    {
        $data['name'] = $request->input("name");
        $data['id'] = $request->input("id");
        $data['tcp_ip'] = $request->input("tcp_ip");
        $data['udp_ip'] = $request->input("udp_ip");
        $data['outside_pc_ip'] = $request->input("outside_pc_ip");
        $data['inside_pc_ip'] = $request->input("inside_pc_ip");
        $data['is_admin'] = $request->input("id_admin",0);
        if ( !$data['id']){
            return $this->error("参数缺失");
        }
        $res = $this->repository->edit($data);
        return $this->res($res);
    }

    public function delete(Request $request)
    {
        $id = $request->input("id");
        if (!$id){
            return $this->error("参数缺失");
        }
        $res = $this->repository->delete($id);
        return $this->res($res);
    }

    public function list(Request $request)
    {
        $list = $this->repository->list();
        return $this->res($list);
    }
    

}
